#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <math.h> 
#include <ctype.h> 
#include <time.h> 
#include <assert.h>

int bin_search(int arr[], int left, int right, int key)
{
	int mid = left + (right - left) / 2;

	while (left <= right)
	{
		if (arr[mid] > key)
		{
			right = mid - 1;
		}

		if (arr[mid] < key)
		{
			left = mid + 1;
		}

		if (arr[mid] == key)
		{
			return mid;
		}

		mid = left + (right - left) / 2;
	}

	return -1;
}

int main()
{
	int arr[10];
	for (int i = 0; i < 10; i++)
	{
		arr[i] = i + 1;
	}

	int left = 0;
	int right = sizeof(arr) / sizeof(arr[0]) - 1;
	int key = 7;
	printf("%d\n", bin_search(arr, left, right, key));

	return 0;
}